<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div,
        p {
            width: 450px;
            height: 30px;
            line-height: 30px;
            color: red;
            background-color: skyblue;

        }
    </style>
</head>

<body>
    <button>显示当前系统时间</button>
    <div>鸡时刻</div>
    <script>
        let btn = document.querySelector('button');
        btn.onclick = function () {
            let result = format();
            let div = document.querySelector('div');
            div.innerHTML = result;
        }

        function format() {
            let d2 = new Date();
            let year = d2.getFullYear();
            let month = d2.getMonth() + 1;
            let date = d2.getDate();
            let day = d2.getDay();
            var week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
            //格式化时分秒
            var h = d2.getHours();
            var m = d2.getMinutes();
            var s = d2.getSeconds();
            var chicken = '会打篮球的鸡为您报时';
            h = h < 10 ? '0' + h : h;
            m = m < 10 ? '0' + m : m;
            s = s < 10 ? '0' + s : s;

            document.querySelector('div').innerHTML = "今天是" + year + '年' + month + '月' + date + '日' + week[day] + ' ' +
                h + ':' + m + ':' + s + '-' + chicken;
            setTimeout(format, 1000);
            return "今天是" + year + '年' + month + '月' + date + '日' + week[day] + ' ' + h + ':' + m + ':' + s + '-' +
                chicken;


        }
    </script>
</body>

</html>